package com.bml.architect.springboot.config;

import com.bml.architect.springboot.utils.Constants;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 发布订阅模式
 */
@Configuration
public class FanoutConfig {

    //声明一个队列
    @Bean
    public Queue fanout_1() {
        return new Queue(Constants.FANOUT_QUEUE1);
    }

    //声明一个队列
    @Bean
    public Queue fanout_2() {
        return new Queue(Constants.FANOUT_QUEUE2);
    }

    //声明一个交换机
    @Bean
    public FanoutExchange fanoutExchange() {

        return new FanoutExchange(Constants.FANOUT_EXCHANGE);
    }

    //绑定队列到交换机
    @Bean
    public Binding bindingQ1() {

        return BindingBuilder.bind(fanout_1()).to(fanoutExchange());
    }

    @Bean
    public Binding bindingQ2() {
        return BindingBuilder.bind(fanout_2()).to(fanoutExchange());
    }


}
